package thread;

public class Race implements Runnable{

    private static String winner;
    private int mile=100;
    private Object object=new Object();

    @Override
    public void run() {
        while (mile>=0){
            synchronized (object) {
                System.out.println(Thread.currentThread().getName() + "-->当前还剩" + mile--);
                if (getResult(mile)) {
                    break;
                }
            }
        }

    }
    public  boolean getResult(int mile){

            if (mile<=0) {
                winner=Thread.currentThread().getName();
                System.out.println("当前的胜利者是：-->"+winner);
                return true;
            }
            return false;


    }

    public static void main(String[] args) {
        Race race=new Race();
        new Thread(race,"乌龟").start();
        new Thread(race,"兔子").start();

    }
}
